﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ART.BLL;
using ART.Common;

namespace ART.Admini.Users
{
    public partial class UserGroupDetail : System.Web.UI.Page
    {
        private ART.BLL.B_UserGroup post = new ART.BLL.B_UserGroup();
        private ART.Model.M_UserGroup model = new ART.Model.M_UserGroup();

        private int postid = 0;

        protected void Page_Load(object sender, EventArgs e)
        {
            postid = LYRequest.GetInt("id", 0);
            if (!IsPostBack)
            {
                InitData();
            }
        }
        private void InitData()
        {
            if (postid > 0)
            {
                model = post.GetModel(postid);
                this.txtPostName.Text = model.GroupName;
                this.txtRemarks.Text = model.Remarks;
                this.txtSort.Text = model.Sort.ToString();
                dropUserType.SelectedValue = model.UserType.ToString();
            }
        }
        protected void btnSave_Click(object sender, EventArgs p1)
        {
            model.UserType = Utils.StrToInt(dropUserType.SelectedValue,0);
            model.GroupName = this.txtPostName.Text.Trim();
            model.Remarks = this.txtRemarks.Text.Trim();
            model.Sort = int.Parse(this.txtSort.Text.Trim());

            if (postid == 0)
            {

                if (this.post.Add(model) > 0)
                {
                    B_operationLog.CreateOperationLog(B_operationLog.operationLogType.Add, "用户组", model.GroupName);
                    MessageBox.JSLoad(sender, "alert('保存成功!');reloadDlg();");
                }
            }
            else
            {
                model.Id = postid;
                if (this.post.Update(model))
                {
                    B_operationLog.CreateOperationLog(B_operationLog.operationLogType.Edit, "用户组", model.GroupName);
                    MessageBox.JSLoad(sender, "alert('保存成功!');reloadDlg();");
                }
            }
        }
        
    }
}
